package edu.sjtu.grid.workflow.schedule;

import edu.sjtu.grid.workflow.facts.Facts;
import edu.sjtu.grid.workflow.facts.Job;
import edu.sjtu.grid.workflow.facts.Mapping;
import edu.sjtu.grid.workflow.facts.PC;
import edu.sjtu.grid.workflow.iterator.UpwardRankIterator;

public class CheapestSchedule extends ScheduleBase{

	public CheapestSchedule(Facts facts) {
		super(facts, ScheduleType.Cheapest);
	}
	
	@Override
	protected void doSchedule()
	{
		PC cheapestPC = this.getFacts().getPcs().getCheepestPC();
		if(cheapestPC == null)
			return;
		
		UpwardRankIterator i = this.getFacts().getAdag().getUpwardRankIterator();
		double fromTime = 0;
		while(i.hasNext())
		{
			Job job = (Job)i.next();
			Mapping mapping = this.getRun().getCheapestMapping(cheapestPC, job, fromTime);
			this.getRun().confirmMapping(mapping);
		}
		this.setResult(true);
	}

}
